<?php
/**
 * Created by PhpStorm.
 * User: t
 * Date: 2024/3/19
 * Time: 17:07
 *
  * @copyright: ©2024 永州微聚商网络科技有限公司
 * @link: https://www.weijuyunke.com
 */

namespace app\admin\controller;

use app\merchant\model\GoodsClassify;
use app\Request;


class Classify
{

    public function classifyList()
    {
        $goodsClassify = new GoodsClassify();
        $list = $goodsClassify->where('status', '>', 0)  ->order('create_time','desc')->select()->toArray();
        $count = $goodsClassify->where('status', '>', 0)  ->order('create_time','desc')->count();
        return adminSuccess('商品分类', ['list' => $list,'count'=> $count]);
    }

    public function addClassify(Request $request)
    {
        $param = $request->param();
        $data = [
            'name' => $param['name'],
            'sort' => $param['sort'],
            'img' => $param['img'],
            'status' => 1,
            'create_time' => time(),
        ];
        $goodsClassify = new GoodsClassify();
        $goodsClassify->insert($data);
        return adminSuccess('添加成功');
    }

    public function editClassify(Request $request)
    {
        $param = $request->param();
        $data = [
            'name' => $param['name'],
            'sort' => $param['sort'],
            'img' => $param['img'],
            'status' => 1,
            'create_time' => time(),
        ];
        $goodsClassify = new GoodsClassify();
        $goodsClassify->where(['id' => $param['id']])->update($data);
        return adminSuccess('修改成功');
    }

    public function upClassify(Request $request)
    {
        $param = $request->param();
        $goodsClassifyModel = new GoodsClassify();
        $goodsClassifyModel->where(['id' => $param['id']])->update(['status' => $param['status']]);
        return adminSuccess('操作成功');
    }

}
